package cn.tannn.tconfig.server.response;

import lombok.Data;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.List;

/**
 * 分页
 *
 * @author <a href="https://tannn.cn/">tnnn</a>
 * @version V1.0
 * @date 2024/5/5 下午3:13
 */
@Data
public class PageResponse <B> implements Serializable {

    /**
     * 页码
     */
    private Integer currentPage;
    /**
     * 数据量
     */
    private Integer pageSize;
    /**
     * 总页数
     */
    private Integer totalPages;
    /**
     * 总记录数
     */
    private Long total;

    /**
     * 数据
     */
    private List<B> rows;


    public PageResponse() {
    }

    public PageResponse(Page<B> rows) {
        this.currentPage = rows.getNumber() + 1;
        this.pageSize = rows.getSize();
        this.totalPages = rows.getTotalPages();
        this.total = rows.getTotalElements();
        this.rows = rows.getContent();
    }

    public PageResponse(Integer currentPage, Integer pageSize, Integer totalPages, Long total, List<B> rows) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalPages = totalPages;
        this.total = total;
        this.rows = rows;
    }
}
